#include<iostream>
#include<string>
#include<memory>
#include <windows.h>
using namespace std;

// 抽象主题接口 subject
class BuyHouse {
    public:
        virtual void buyHouse() = 0;
        virtual ~BuyHouse() = default;
};

// 真实主题 RealSubject
class RealBuyHouse : public BuyHouse {
    private:
        string buyerName;
    public:
        RealBuyHouse(const string &name) : buyerName(name) {}

        void buyHouse() override
        {
            cout << buyerName << " 正在购买一套心仪的房子..." << endl;
        }
};

// 代理类 Proxy
class BuyHouseProxy : public BuyHouse {
    private:
        shared_ptr<RealBuyHouse> realBuyer;
        string buyerName;
    public:
        BuyHouseProxy(const string &name)
        {
            realBuyer = make_shared<RealBuyHouse>(name);
        }

        void buyHouse() override
        {
            preWork();
            realBuyer->buyHouse();
            postWork();
        }

    private:
        void preWork()
        {
            cout << "🏠 房产中介：帮客户找合适房源，安排看房..." << endl;
            cout << "🏠 房产中介：核实房屋信息，准备合同..." << endl;
        }

        void postWork()
        {
            cout << "🏦 房产中介：协助贷款、过户、交房..." << endl;
            cout << "✅ 房产中介：交易完成，客户非常满意！" << endl;
        }
};

// 🎯 客户端（Client）
int main()
{
    SetConsoleOutputCP(65001);
    shared_ptr<BuyHouse> buyer = make_shared<BuyHouseProxy>("张三");
    buyer->buyHouse();
    return 0;
}